using MeetingManagement.Domain.Entities;
using Microsoft.Extensions.DependencyInjection;

namespace MeetingManagement.Infrastructure.Common;

public static class SeedAdminUser
{
    public static void EnsureAdmin(IServiceProvider serviceProvider, string adminEmail, string adminUserName, string adminRole, string passwordHash)
    {
        using var scope = serviceProvider.CreateScope();
        var context = scope.ServiceProvider.GetRequiredService<MeetingManagementDbContext>();
        if (!context.Users.Any(u => u.Email == adminEmail))
        {
            var admin = User.Create(adminUserName, adminEmail, passwordHash, adminRole);
            context.Users.Add(admin);
            context.SaveChanges();
        }
    }
}
